<?php use app\admin\model\CateGory; ?>
<style type="text/css">
	table img{
		width: 50px;
		height: 50px;
		position: absolute;
		margin-top: -10px;
	}
	.layui-table-cell{
		overflow: visible;

	}

</style>
<div style="padding: 15px;">
<a class="layui-btn"  href="/admin/good/addGood">添加商品</a>

<div id="table" style="width:100%"></div>
</div>
<script type="text/html" id="bar">

  <a class="layui-btn layui-btn-xs"  lay-event="edit">编辑</a>
 <a class="layui-btn layui-btn-danger layui-btn-xs"   lay-event="del">删除</a>
</script>

<script type="text/javascript">
	
	layui.use('table', function(){
  table = layui.table;

  tableobj = table.render({
    elem: '#table'
    ,url:'/admin/good/getInfo'
   
    ,cols: [
   	[
     // {field:'update_time', title: '更新时间',unresize:true}
      {field:'id',width:100, type:'normal', title: 'ID', }
      ,{field:'name',width:150,title: '商品名称'}
     ,{style:"height:68px;overflow:visible;",width:150,title: '商品图片',templet:function(data){
     	return "<img src='__upload__"+data.logo+"' />"
     }}
     ,{field:'price',width:100,title: '价格'}
     ,{field:'good_num',width:100,title: '库存'}
     ,{width:100,title: '分类',templet:function(data){
     	// return "{:CateGory::getCategoryName("+data.category_id+")}";
     	
     	return data.category_id;
     }}
 ,{field:'create_time',width:170,  title: '创建时间'}

     ,{field:'update_time', width:170, title: '更新时间'}
      ,{field:'active', title: '操作',toolbar: '#bar'}
    ]]


    ,page:{
    	layout:['prev','page','next','count','skip'],
    	prev:'上一页',
    	next:'下一页',
    	limit:5,

    }

     ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
     	
     	
     	return {
     		"code":res.code,
     		"count": res.total,
    		"data": res.good //解析数据列表
     	}

    }
  });
   table.on('tool()', function(obj){
    var data = obj.data;
  	if(obj.event === 'edit'){

      window.location.href = "/admin/good/edit/"+data.id;
    }
    if(obj.event === 'del'){

     layui.use('layer', function(){
     var layer = layui.layer;
       layer.confirm('确定要删除', {
        btn: ['确定', '取消'] //可以无限个按钮
       
      }, function(index, layero){
           $.get('/admin/good/del/'+data.id,function(res){
        
        window.location.href = "/admin/good"
      })
      }, function(index){
        return;
      });
  })
      
    }
  });

});
</script>

</div>